package com.yutian.springbootfreemarker.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
 
import javax.annotation.PostConstruct;
 
@Configuration
public class FreeMarkerConfig {
    @Autowired
    private freemarker.template.Configuration configuration;

    @Value("${server.servlet.contextPath:/}")
    private String contextPath;

    @PostConstruct
    public void setConfigure() throws Exception {
        configuration.setSharedVariable("contextPath", contextPath);
    }
}
 
